# -*- coding: UTF-8 -*-
# vim: expandtab sw=4 ts=4 sts=4
#
#     This file is part of IMAPylator
#
#    IMAPylator is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    Foobar is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with Foobar.  If not, see <http://www.gnu.org/licenses/>.


'''
    Print headers in match function
'''

import IMAPylatorMatch

class DumpHeaders(IMAPylatorMatch.IMAPylatorMatch):

    def matchFolder(self, folder, opt=None):
        '''
        folder name to check.
        example: -F Sent return True if current folder name il "Sent"
        '''
        if opt:
            f = opt
        else:
            return True

        if folder == f:
            return True
        return False

    def match(self, headers, flags, internal_date, folder, opt=None):
        '''
        Headers to dump a comma-separated list
        example: -M To,From,Subject

        return False
        '''
        
        opt_headers = opt.split(',')
        for h in opt_headers:
            if headers.has_key(h):
                print "%s: %s" % (h, headers[h])

        return False

    def action(self, message, flags, folder, internal_date, opt=None):
        '''
        None

        return skip
        '''
        
        return "skip"
